<%@ page import="domain.Order_Good" %>
<%@ page import="dao.Dao" %>
<%@ page import="domain.User" %><%--
  Created by IntelliJ IDEA.
  User: wangh
  Date: 2020/12/27
  Time: 13:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <!-- 使用Edge最新的浏览器的渲染方式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- viewport视口：网页可以根据设置的宽度自动进行适配，在浏览器的内部虚拟一个容器，容器的宽度与设备的宽度相同。
    width: 默认宽度与设备的宽度相同
    initial-scale: 初始的缩放比，为1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>订单列表</title>
    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>
    <script>
        function updateLogistics(orderid) {
            let elementById = document.getElementById(orderid);
            console.log(elementById.innerHTML);
            if (elementById.innerHTML == "已发货") {
                alert("您已发货，请不要重复发货！")
            } else if (confirm("确认发货吗？")) {
                location.href = "${pageContext.request.contextPath}/updateLogisticsServlet?orderid=" + orderid;
            }
        }
        function updateOrderInfo(orderid){
            let elementById = document.getElementById(orderid);
            if (elementById.innerHTML == "已发货") {
                alert("您已发货，不能再修改订单！")
            } else if (confirm("确认修改订单吗？")) {
                location.href = "${pageContext.request.contextPath}/updateOrderInfo.jsp?orderid=" + orderid;
            }
        }
    </script>
</head>
<body>
<div class="logoBar"
     style="height: 75px;background: #1d7ad9;font-size: 35px;font-weight: bolder;padding-left: 100px;padding-top: 12px;color: white;">
    电脑销售管理后台
</div>
<div class="container">
    <h3 style="text-align: center">订单列表</h3>
    <div style="float: left;margin: 5px;">
        <form action="${pageContext.request.contextPath}/findOrderByOrderIdServlet" class="form-inline" method="post">
            <div class="form-group">
                <label for="orderid">订单号查询:</label>
                <input type="text" placeholder="请输入订单号" class="form-control" id="orderid" name="orderid">
            </div>
            <button type="submit" class="btn btn-default">查询</button>
        </form>
    </div>
    <div style="float: right;margin: 5px;">
        <a class="btn btn-primary" href="${pageContext.request.contextPath}/AdminIndex.jsp">管理员主页</a>
    </div>
    <form>
        <table border="1" class="table table-bordered table-hover">
            <tr class="success">
                <th>订单号</th>
                <th>商品名称</th>
                <th>商品图片</th>
                <th>商品数量</th>
                <th>商品总价</th>
                <th>付款方式</th>
                <th>订单状态</th>
                <th>收货地址</th>
                <th>收货人</th>
                <th>电话号码</th>
                <th>物流状态</th>
                <th>操作</th>
                <th>发货</th>
            </tr>
            <c:if test="${ordersByOrderId==null}">
                <c:forEach items="${orders}" var="orderForAdmin" varStatus="s">
                    <tr>
                        <td>${orderForAdmin.orderid}</td>
                        <td>${orderForAdmin.cname}</td>
                        <td><img src="${orderForAdmin.cimage}" style="width: 120px;height: 61.05px;"/></td>
                        <td>${orderForAdmin.snumber}</td>
                        <td>${orderForAdmin.ordertotal}</td>
                        <td>${orderForAdmin.paymode}</td>
                        <td>${orderForAdmin.orderstate}</td>
                        <td>${orderForAdmin.address}</td>
                        <td>${orderForAdmin.receivename}</td>
                        <td>${orderForAdmin.tele}</td>
                        <c:if test="${orderForAdmin.logisticsstatus=='未发货'}">
                            <td>
                                <button type="button" class="btn btn-danger"
                                        id="${orderForAdmin.orderid}">${orderForAdmin.logisticsstatus}</button>
                            </td>
                        </c:if>
                        <c:if test="${orderForAdmin.logisticsstatus!='未发货'}">
                            <td>
                                <button type="button" class="btn btn-success"
                                        id="${orderForAdmin.orderid}">${orderForAdmin.logisticsstatus}</button>
                            </td>
                        </c:if>
                        <td><a class="btn btn-default btn-sm"
                               href="javascript:updateOrderInfo(${orderForAdmin.orderid});">修改订单</a></td>
                        <td><a class="btn btn-default btn-sm"
                               href="javascript:updateLogistics(${orderForAdmin.orderid});">发货</a></td>
                    </tr>
                </c:forEach>
            </c:if>
            <c:if test="${ordersByOrderId!=null}">
                <tr>
                    <td>${ordersByOrderId.orderid}</td>
                    <td>${ordersByOrderId.cname}</td>
                    <td><img src="${ordersByOrderId.cimage}" style="width: 120px;height: 61.05px;"/></td>
                    <td>${ordersByOrderId.snumber}</td>
                    <td>${ordersByOrderId.ordertotal}</td>
                    <td>${ordersByOrderId.paymode}</td>
                    <td>${ordersByOrderId.orderstate}</td>
                    <td>${ordersByOrderId.address}</td>
                    <td>${ordersByOrderId.receivename}</td>
                    <td>${ordersByOrderId.tele}</td>
                    <c:if test="${ordersByOrderId.logisticsstatus=='未发货'}">
                        <td>
                            <button type="button" class="btn btn-danger"
                                    id="${ordersByOrderId.orderid}">${ordersByOrderId.logisticsstatus}</button>
                        </td>
                    </c:if>
                    <c:if test="${ordersByOrderId.logisticsstatus!='未发货'}">
                        <td>
                            <button type="button" class="btn btn-success"
                                    id="${ordersByOrderId.orderid}">${ordersByOrderId.logisticsstatus}</button>
                        </td>
                    </c:if>
                    <td><a class="btn btn-default btn-sm"
                           href="javascript:updateOrderInfo(${ordersByOrderId.orderid});">修改订单</a></td>
                    <td><a class="btn btn-default btn-sm"
                           href="javascript:updateLogistics(${ordersByOrderId.orderid});">发货</a></td>
                </tr>
            </c:if>
        </table>
    </form>
</div>
</body>
</html>


